﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using BLL;

public partial class QuarterPlan_QuarterAttachmentPath : System.Web.UI.Page
{
    string path = HttpContext.Current.Server.MapPath("~/") + @"Upload\";
    QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
    MonthPlanManager dllMonthPlanManager = new MonthPlanManager();
    UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
    WeekPlanofManager dllWeekPlanofManager = new WeekPlanofManager();
    UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// 提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        int _planType = Utility.HttpHelp.getParamsInt("PlanType");
        if (this.fupAttachmentPath.FileName.Length>0)
        {
            //获得附件文件名
            string _filename = this.fupAttachmentPath.FileName;
            //判断是否存在
            if (System.IO.File.Exists(path + _filename))
            {
                System.IO.File.Delete(path + _filename);
            }
            
            this.fupAttachmentPath.SaveAs(path + _filename);
            //构造数组
            object[] _planRecord = new object[2];
            //页面传年计划ID
                         
            int result = 0;
            _planRecord[1] = path +  _filename;//
            if (_planType == 1)//年计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllQuarterPlanofManager.edit(QuarterPlanofManager.field.QuarterPlanId.ToString(), _planRecord);
            }
            if (_planType == 2 || _planType == 4)//月计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllMonthPlanManager.edit(MonthPlanManager.field.MonthPlanId.ToString(), _planRecord);
            }
            if (_planType == 3 || _planType == 5)//周计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllWeekPlanofManager.edit(WeekPlanofManager.field.WeekPlanId.ToString(), _planRecord);
            }
            if (_planType == 6)//员工月计划发送类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanMonth.edit(UserPlanMonth.field.MonthPlanId.ToString(), _planRecord);
            }
            if (_planType == 7)//员工周计划发送类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanWeek.edit(UserPlanWeek.field.WeekPlanId.ToString(), _planRecord);
            }
            if (_planType == 8)//员工周计划发送类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanWeek.edit(UserPlanWeek.field.WeekPlanId.ToString(), _planRecord);
            }
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("上传文件未成功，请重试！");
            }
            else
            {
                if (_planType == 1)
                {
                    
                    Page.RegisterStartupScript("alert",
              "<script language=javascript>window.opener.location='../QuarterPlan/SendedQuarterPlan.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 2 )
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../Month/YiFaMonthPlan.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 3)
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../Week/SendWeekPlan.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 4)
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../Month/MonthPlanAdd.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 5)
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../Week/WeekPlanAdd.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 6)
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../UserPlanMonth/SendUserPlanMonth.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 7)
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../UserPlanWeek/UserPlanWeekAdd.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 8)
                { 
                    Page.RegisterStartupScript("alert",
          "<script language=javascript>window.opener.location='../UserPlanWeek/SendUserPlanWeek.aspx';alert('上传成功！');window.close();</script>");
                }
            }
        }
        else
        {
            //构造数组
            object[] _quaterRecord = new object[2];
            _quaterRecord[1] = "";
            _quaterRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");

            int result = dllQuarterPlanofManager.edit(QuarterPlanofManager.field.QuarterPlanId.ToString(), _quaterRecord);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("上传文件未成功，请重试！");
            }
            else
            {
                if (_planType == 1)
                {
                    Utility.HttpHelp.closeWindow("../QuarterPlan/SendedQuarterPlan.aspx", Page);
                }
                if (_planType == 2)
                {
                    Utility.HttpHelp.closeWindow("../Month/YiFaMonthPlan.aspx", Page);
                }
                if (_planType == 3)
                {
                    Utility.HttpHelp.closeWindow("../Week/SendWeekPlan.aspx", Page);
                }
                if (_planType == 4)
                {
                    Utility.HttpHelp.closeWindow("../Month/MonthPlanAdd.aspx", Page);
                }
                if (_planType == 5)
                {
                    Utility.HttpHelp.closeWindow("../Week/WeekPlanAdd.aspx", Page);
                }
                if (_planType == 6)
                {
                    Utility.HttpHelp.closeWindow("../UserPlanMonth/SendUserPlanMonth.aspx", Page);
                }
                if (_planType == 7)
                {
                    Utility.HttpHelp.closeWindow("../UserPlanWeek/UserPlanWeekAdd.aspx", Page);
                }
                if (_planType == 8)
                {
                    Utility.HttpHelp.closeWindow("../UserPlanWeek/SendUserPlanWeek.aspx", Page);
                }
            }
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("AttachmentPath.aspx");
    }
}
